package org.gten.gegedexin.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.gten.gegedexin.Data.QueryInformation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ConditionalQuery {
    @Autowired
    ReadMailList readMailList;
    @Autowired
    QueryMail queryMail;

    public void queryWithConditional(QueryInformation queryInf){
        readMailList.settingWorking(queryInf.getStatus()-1);
        queryMail.queryWithSender(readMailList.getworking(),queryInf.getAccount());
        queryMail.queryWithSender(queryMail.getList(),queryInf.getTitle());
    }

    public JSONArray returnPage(int page){
        JSONArray jsonPage = queryMail.getList();
        for(int i=0+(page-1)*10;i<page*10;i++){
            if(i>=queryMail.getList().size())break;
            jsonPage.add(queryMail.getList().get(i));
        }
        JSONObject numJSON = new JSONObject();
        numJSON.put("totalcount",queryMail.getList().size());
        jsonPage.add(numJSON);
        return jsonPage;
    }
}
